package com.ruihu.admin.module.business.tasknode.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import com.ruihu.admin.module.business.tasknode.domain.dto.NodeInstProcessDefectAddDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.NodeInstProcessDefectDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.NodeInstProcessDefectUpdateDTO;
import lombok.Data;

import java.util.Objects;

/**
 * [  ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2023-02-22 11:44:41
 * @since JDK1.8
 */

@Data
@TableName("t_node_inst_process_defect")
public class NodeInstProcessDefectEntity extends BaseEntity {

    /**
     * sub_task_id
     */
    private Long subTaskId;

    /**
     * task_node_inst_id
     */
    private Long taskNodeInstId;

    /**
     * process_relation_id
     */
    private Long processRelationId;

    /**
     * defect_type_id
     */
    private Long defectTypeId;

    /**
     * defect_type_name
     */
    private String defectName;

    /**
     * create_by
     */
    private Long createBy;


    /**
     * update_by
     */
    private Long updateBy;


    public static NodeInstProcessDefectEntity convertToNodeInstProcessDefectEntity(NodeInstProcessDefectAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }

        NodeInstProcessDefectEntity entity = new NodeInstProcessDefectEntity();
        entity.setProcessRelationId(addDTO.getProcessRelationId());
        entity.setDefectTypeId(addDTO.getDefectTypeId());
        entity.setDefectName(addDTO.getDefectName());
        return entity;
    }


    public static NodeInstProcessDefectEntity convertToNodeInstProcessDefectEntity(NodeInstProcessDefectUpdateDTO updateDTO) {
        if (updateDTO == null) {
           return null;
        }

        NodeInstProcessDefectEntity entity = new NodeInstProcessDefectEntity();
        entity.setId(updateDTO.getId());
        entity.setProcessRelationId(updateDTO.getProcessRelationId());
        entity.setDefectTypeId(updateDTO.getDefectTypeId());
        entity.setDefectName(updateDTO.getDefectName());
        return entity;
    }

    public static NodeInstProcessDefectEntity convertToNodeInstProcessDefectEntity(NodeInstProcessDefectDTO dto) {
        if (dto == null) {
           return null;
        }

        NodeInstProcessDefectEntity entity = new NodeInstProcessDefectEntity();
        entity.setId(dto.getId());
        entity.setProcessRelationId(dto.getProcessRelationId());
        entity.setDefectTypeId(dto.getDefectTypeId());
        entity.setDefectName(dto.getDefectName());
        entity.setCreateBy(dto.getCreateBy());
        entity.setCreateTime(dto.getCreateTime());
        entity.setUpdateBy(dto.getUpdateBy());
        entity.setUpdateTime(dto.getUpdateTime());
        return entity;
    }

    public static NodeInstProcessDefectEntity copyIgnoreNullAndEmpty(NodeInstProcessDefectEntity sourceEntity, NodeInstProcessDefectEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;
        if (Objects.nonNull(sourceEntity.getId())) {
           destEntity.setId(sourceEntity.getId());
        }
        if (Objects.nonNull(sourceEntity.getProcessRelationId())) {
           destEntity.setProcessRelationId(sourceEntity.getProcessRelationId());
        }
        if (Objects.nonNull(sourceEntity.getDefectTypeId())) {
           destEntity.setDefectTypeId(sourceEntity.getDefectTypeId());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getDefectName())) {
           destEntity.setDefectName(sourceEntity.getDefectName());
        }
        if (Objects.nonNull(sourceEntity.getCreateBy())) {
           destEntity.setCreateBy(sourceEntity.getCreateBy());
        }
        if (Objects.nonNull(sourceEntity.getCreateTime())) {
           destEntity.setCreateTime(sourceEntity.getCreateTime());
        }
        if (Objects.nonNull(sourceEntity.getUpdateBy())) {
           destEntity.setUpdateBy(sourceEntity.getUpdateBy());
        }
        if (Objects.nonNull(sourceEntity.getUpdateTime())) {
           destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        }
        return destEntity;
    }
}
